import * as PIXI from '../libs/pixi.4.8.0';
import Main from "./game/modules/core/view/vc/Main";
import {fgui} from "../libs/fairygui.1.3.0";

const {pixelRatio, windowHeight, windowWidth} = wx.getSystemInfoSync();

export const designWidth = 640;
export const designHeight = 1136;
export const host = 'https://p3fzyvjz.qcloud.la';
export const shareData = {
    title: '指尖灌篮'
};


PIXI.utils.skipHello();
PIXI.utils.isWebGLSupported = () => {
    return canvas.getContext('webgl')
}

PIXI.interaction.InteractionManager.prototype.mapPositionToPoint = (point, x, y) => {
    point.x = x * pixelRatio
    point.y = y * pixelRatio
}

function run() {
    const options = {
        backgroundColor: 0x0e385b,
        width: windowWidth * pixelRatio,
        height: windowHeight * pixelRatio,
        view: canvas,
        antialias: true,
        resolution: 1
    };
    new Main(options);
}

function showModal(msg) {
    wx.showModal({
        title: '提示',
        content: msg,
        showCancel: false,
    });
}

function request(url, data, success, fail) {
    wx.request({
        url: url,
        data: data,
        method: 'GET',
        dataType: 'json',
        success: (res) => {
            if (success) {
                success(res.data);
            }
        },
        fail: (res) => {
            if (fail) {
                fail(res.data);
            }
        }
    });
}

export function login() {
    wx.login({
        success: (res) => {
            run();
        },
        fail: (res) => {
            showModal(res.errMsg);
        }
    });
}

// 保持屏幕常亮
wx.setKeepScreenOn({
    keepScreenOn: true
});

wx.showShareMenu();
// 转发
wx.onShareAppMessage(function () {
    return {
        title: shareData.title,
        imageUrl: canvas.toTempFilePathSync({
            destWidth: designWidth,
            destHeight: designHeight
        })
    }
})

login();

